package cn.it.controller;

import cn.it.entity.PageResult;
import cn.it.entity.QueryPageBean;
import cn.it.entity.Result;
import cn.it.pojo.Permission;
import cn.it.service.PermissionService;
import com.alibaba.dubbo.config.annotation.Reference;
import jdk.nashorn.internal.ir.ReturnNode;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;

@RequestMapping("/permission")
@RestController
public class PermissionController {


    @Reference
    private PermissionService permissionService;

    @RequestMapping(value = "/findPage",name = "权限分页查询")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return permissionService.findPage(queryPageBean);
    }

    @RequestMapping(value = "/add",name = "添加权限")
    public Result add(@RequestBody Permission permission){
        try {
            permissionService.add(permission);
            return new Result(true,"添加权限成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"添加权限失败");
        }
    }


    @RequestMapping(value = "/deleteById",name = "删除权限")
    public Result deleteById(Integer id){
        try {
            permissionService.deleteId(id);
            return new Result(true,"删除权限成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除权限失败");
        }
    }

    //findById
    @RequestMapping(value = "/findById",name = "回显权限信息")
    public Result findById(Integer id){
        try {
            Permission permission = permissionService.findById(id);
            return new Result(true,"查询权限成功",permission);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询权限失败");
        }
    }

}
